﻿///<copyright>
/// Copyright © 2009 Stephen Styrchak. All Rights Reserved.
///</copyright>
using System;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Ferpect.ComponentModel
{
    public class KeyboardInputState
    {
        private KeyboardState currentKeyboard;
        private KeyboardState previousKeyboard;

        public KeyboardInputState()
        {
            this.Update();
            this.previousKeyboard = this.currentKeyboard;
        }

        public bool IsKeyDown(Keys key)
        {
            return this.currentKeyboard.IsKeyDown(key);
        }

        public bool IsKeyUp(Keys key)
        {
            return this.currentKeyboard.IsKeyUp(key);
        }

        public bool IsNewKeyPress(Keys key)
        {
            return this.currentKeyboard.IsKeyDown(key) && this.previousKeyboard.IsKeyUp(key);
        }

        public bool IsNewKeyRelease(Keys key)
        {
            return this.currentKeyboard.IsKeyUp(key) && this.previousKeyboard.IsKeyDown(key);
        }

        public Keys[] GetCurrentPressedKeys()
        {
            return this.currentKeyboard.GetPressedKeys();
        }

        public Keys[] GetPreviousPressedKeys()
        {
            return this.previousKeyboard.GetPressedKeys();
        }

        public void Update()
        {
            this.previousKeyboard = this.currentKeyboard;
            this.currentKeyboard = Keyboard.GetState();
        }
    }
}
